//
//  GeDiaoCell.m
//  Style
//
//  Created by dllo on 15/9/23.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#define ScreenWidth          [[UIScreen mainScreen] bounds].size.width
#define ScreenHeight         [[UIScreen mainScreen] bounds].size.height
#define ViewWidth(v)                        v.frame.size.width
#define ViewHeight(v)                       v.frame.size.height

#import "GeDiaoCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "GeDiaoModel.h"
@implementation GeDiaoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.frontLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.frontLabel];

        
        self.strHpTitleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.strHpTitleLabel];

        
        self.strOriginalImgUrlView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.strOriginalImgUrlView];

        
        self.strAuthorLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.strAuthorLabel];

        
        self.strAuthorLabel2 = [[UILabel alloc] init];
        [self.contentView addSubview:self.strAuthorLabel2];

        
        self.label = [[UILabel alloc] init];
        self.label.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview:self.label];
        
        self.monthLabel = [[UILabel alloc] init];
        [self.label addSubview:self.monthLabel];
 
        
        self.dataLabel = [[UILabel alloc] init];
        [self.label addSubview:self.dataLabel];
        
        self.view = [[UIView alloc] init];
        [self.contentView addSubview:self.view];
        
        self.strContentView = [[UIView alloc] init];
        [self.contentView addSubview:self.strContentView];

        
        self.strContentLabel = [[UILabel alloc] init];
        [self.strContentView addSubview:self.strContentLabel];

        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.frontLabel.frame = CGRectMake(ScreenWidth / 30, ScreenWidth / 30, ScreenWidth / 5, ScreenHeight / 20);
    
    self.strHpTitleLabel.frame = CGRectMake(ScreenWidth / 10 * 1.5, ScreenWidth / 30, ScreenWidth / 2, ScreenHeight / 20);
    
    self.strOriginalImgUrlView.frame = CGRectMake(ScreenWidth / 30, ScreenHeight / 10, ScreenWidth - ScreenWidth / 15, ScreenHeight / 2.5);
    
    self.strAuthorLabel.frame = CGRectMake(ScreenWidth / 5 * 3.1, ScreenHeight / 10 * 5.2, ScreenWidth / 3, ScreenHeight / 20);
    
    self.strAuthorLabel2.frame = CGRectMake(ScreenWidth / 5 * 3.1, ScreenHeight / 10 * 5.6, ScreenWidth / 3, ScreenHeight / 20);
    
    self.label.frame = CGRectMake(ScreenWidth / 2.5, ScreenHeight / 2.2, ScreenWidth / 5, ScreenWidth / 5);
    self.label.layer.cornerRadius = ScreenWidth / 10;
    self.label.layer.masksToBounds = YES;
    
    self.monthLabel.frame = CGRectMake(0, ScreenWidth / 75, ScreenWidth / 5, ScreenWidth / 10);
    self.monthLabel.textAlignment = 1;
    
    self.dataLabel.frame = CGRectMake(0, ScreenWidth / 11 , ScreenWidth / 5, ScreenHeight / 18);
    self.dataLabel.textAlignment = 1;
    
    self.view.frame = CGRectMake(ScreenWidth / 2, ScreenHeight / 1.77, 2, ScreenHeight / 15);
    self.view.backgroundColor = [UIColor blackColor];
    
    self.strContentView.layer.borderWidth = 0.8;
    self.strContentView.layer.cornerRadius = 10;
    self.strContentView.layer.masksToBounds = YES;
    if (self.strContentLabel.text.length >= 90) {
        if (ScreenWidth < 375) {
            self.strContentView.frame = CGRectMake(ScreenWidth / 30, ScreenHeight / 10 * 6.3, ScreenWidth / 3 * 2.8, ScreenHeight / 10 * 1.9);
            self.strContentLabel.frame = CGRectMake(7, 0, ScreenWidth / 3 * 2.7, ScreenHeight / 10 * 2.8);
        } else
        {
            self.strContentView.frame = CGRectMake(ScreenWidth / 30, ScreenHeight / 10 * 6.3, ScreenWidth / 3 * 2.8, ScreenHeight / 10 * 1.9);
            self.strContentLabel.frame = CGRectMake(7, 0, ScreenWidth / 3 * 2.7, ScreenHeight / 10 * 2.3);
        }
    } else if (self.strContentLabel.text.length >= 60)
    {
        self.strContentView.frame = CGRectMake(ScreenWidth / 30, ScreenHeight / 10 * 6.3, ScreenWidth / 3 * 2.8, ScreenHeight / 10 * 1.9);
        self.strContentLabel.frame = CGRectMake(7, 0, ScreenWidth / 3 * 2.7, ScreenHeight / 10 * 2);
    } else if (self.strContentLabel.text.length >= 30)
    {
        self.strContentView.frame = CGRectMake(ScreenWidth / 30, ScreenHeight / 10 * 6.3, ScreenWidth / 3 * 2.8, ScreenHeight / 10 * 1.9);
        self.strContentLabel.frame = CGRectMake(7, 0, ScreenWidth / 3 * 2.7, ScreenHeight / 10 * 1.7);
    } else
    {
        self.strContentView.frame = CGRectMake(ScreenWidth / 30, ScreenHeight / 10 * 6.3, ScreenWidth / 3 * 2.8, ScreenHeight / 10 * 1.9);
        self.strContentLabel.frame = CGRectMake(7, 0, ScreenWidth / 3 * 2.7, ScreenHeight / 10 * 1.3);
        
    }

}

- (void)setGEDIAOModel:(GeDiaoModel *)GEDIAOModel
{
    NSString *front = [GEDIAOModel.strHpTitle substringToIndex:4];
    self.frontLabel.text = front;
    self.frontLabel.textColor = [UIColor darkGrayColor];
    self.strHpTitleLabel.text = GEDIAOModel.strMarketTime;
    self.strHpTitleLabel.textColor = [UIColor darkGrayColor];
    
    //    self.strHpTitleLabel.text = main_model.strHpTitle;
    
    [self.strOriginalImgUrlView sd_setImageWithURL:[NSURL URLWithString:GEDIAOModel.strOriginalImgUrl] placeholderImage:[UIImage imageNamed:@"zhanweitu"]];
    
    NSArray *arr = [GEDIAOModel.strAuthor componentsSeparatedByString:@"&"];
    self.strAuthorLabel.text = arr[0];
    self.strAuthorLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.strAuthorLabel.numberOfLines = 0;
    self.strAuthorLabel.font = [UIFont systemFontOfSize:14];
    self.strAuthorLabel.textAlignment = NSTextAlignmentRight;
    
    self.strAuthorLabel2.text = arr[1];
    self.strAuthorLabel2.lineBreakMode = NSLineBreakByWordWrapping;
    self.strAuthorLabel2.numberOfLines = 0;
    self.strAuthorLabel2.font = [UIFont systemFontOfSize:14];
    self.strAuthorLabel2.textAlignment = NSTextAlignmentRight;
    
    
    self.strContentLabel.text = GEDIAOModel.strContent;
    self.strContentLabel.lineBreakMode = NSLineBreakByWordWrapping;
    self.strContentLabel.numberOfLines = 0;
    self.strContentLabel.font = [UIFont systemFontOfSize:14];
    
    self.dataLabel.text = [GEDIAOModel.strMarketTime substringToIndex:7];
    self.dataLabel.textColor = [UIColor whiteColor];
    
    
    self.monthLabel.text = [GEDIAOModel.strMarketTime substringFromIndex:8];
    
    self.monthLabel.textColor = [UIColor whiteColor];
    if (ScreenWidth < 375) {
        self.dataLabel.font = [UIFont systemFontOfSize:11];
        self.monthLabel.font = [UIFont boldSystemFontOfSize:30];
    } else
    {
        self.dataLabel.font = [UIFont systemFontOfSize:14];
        self.monthLabel.font = [UIFont boldSystemFontOfSize:34];
    }
    

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    self.strOriginalImgUrlView.userInteractionEnabled = YES;
    [self.strOriginalImgUrlView addGestureRecognizer:tap];

}

- (void)handleTap:(UITapGestureRecognizer *)sender
{
    NSLog(@"jjjjjjjj");
    NSNotificationCenter *ViewCenter = [NSNotificationCenter defaultCenter];
    [ViewCenter postNotificationName:@"view" object:self.strOriginalImgUrlView];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
